<script type="text/javascript" src="jquery.js"> </script>		
<script type="text/javascript" src="prototype.js"> </script>
<script type="text/javascript" src="JForm.js"></script>

<%
	//get all actions
	List allActions = RoleAssignService.$.getAllActions();
	List highSelActions = RoleAssignService.$.getSelActions();
	//build a json constructor:
	//{'超级用户'：{'sel':[],'unsel':[]},'业务经理'：{'sel':[],'unsel':[]},'业务员'：{'sel':[],'unsel':[]}}
//按照不同的filter，
//查询ActionGroup得到已有权限
//查询Action得到所有权限
	//ActiongroupDAO.$.findByGroupid()
	//Actiongroup需要重新反向工程一下
 %>

	<script type="text/javascript">
	dojo.require("dojo.parser");
	  dojo.require("dojo.dnd.Container");
	  dojo.require("dojo.dnd.Manager");
	  dojo.require("dojo.dnd.Source");
	
	var selectedArray = ['用户管理', '合同管理', '创建人才', '创建企业'];
	var unselectedArray = ['员工考核'] ;//= ['录入合同','分配任务'];
	
	  function initDND(){
	    var c1;
	    c1 = new dojo.dnd.Source("container1");
	    c1.insertNodes(false, selectedArray);
	    
   	    var c2;
	    c2 = new dojo.dnd.Source("container2");
	    c2.insertNodes(false, unselectedArray);
	  };
	
	  dojo.addOnLoad(initDND);
</script>

<fieldset>
	<legend>分配权限</legend>
	<form id="role_form" action="roleAssign.do">
		<table align="left" border="1px">
			<tr>
				<th><font>用户组</font></th>
				<td>
					<select id="personType" class="required" name="personType">
						<option>超级管理员</option>
						<option>业务员</option>
						<option>业务经理</option>
						<%
							//List accessGroups = (List) AccessGroupService.$.getGroups(); 
							//for(int i = 0; i < accessGroups.size(); i++) {
						%>
	                   <option><%// accessGroups.get(i)%> </option>
						<%
							//}
						 %>
	               </select>
				</td>
			</tr>
			<tr>
				<td colspan="2">
				    <div id="dragLists">
						<div style="float: left; margin: 5px;">
							<h3>Selected</h3>
							<table border="1px;">
								<tr>
									<td>
								    	<div id="container1" class="dndContainer">
								    	</div>
									</td>
								</tr>
							</table>
  					 	</div>
		  				<div style="float: left; margin: 5px;">
							<h3>Unselected</h3>
							<table border="1px;">
								<tr>
									<td>
										<div id="container2" class="dndContainer"></div>
										    <!-- 
										    <div dojoType="dojo.dnd.Source" jsId="c2" class="dndContainer">
										      <div class="dojoDndItem">Item <strong>X</strong></div>
										      <div class="dojoDndItem">Item <strong>Y</strong></div>
										      <div class="dojoDndItem">Item <strong>Z</strong></div>
										    </div>
										     -->
									</td>
								</tr>
							</table>
		  				</div>
					</div>
				</td>
			</tr>
			<tr>	
				<td>
					<input type="hidden" id="selrole" name="selrole" value=""/>
					<input type="hidden" id="unselrole" name="unselrole" value=""/>
					<input class='button' type="button" value="保存" onclick="assignRole()">
				</td>
				<td>
					<input class='button' type="button" value="取消" onclick="actionPage('la_role_assign.jsp')">
				</td>
			</tr>
		</table>
	</form>
</fieldset>
<div id="add_Result">
</div>
<script type="text/javascript">
	var JForm = Class.create();       
	Object.extend(JForm.prototype, {           
		validate : function(DOMTREE){
			var userid = $('userid_add').value;
			var uiRegExp = new RegExp("^[a-z]*", "i")
			if(!uiRegExp.test(userid)) {
				alert('userid is invalid');
				return false;
			}
						
			//myRegExp.exec('a'),  return the result array
			
			return true;
	    }
	});

	formValidate = function(DOMTREE) {
		var validator = new JForm();
		return validator.validate(DOMTREE);
	}
	callBack = function(resp) {
		var resText = resp.responseText;
		if(resText.indexOf('UserException:')>-1) {
			//alert('UserException');
			$('right').innerHTML = resText;
		} else {
			$('right').innerHTML = resText;
		}
		var successful = false;
		if(successful) {
			var sp = document.createElement("textArea");
			sp.innerHTML = "success";
			var footerDiv = document.getElementById('copyright');
			footerDiv.appendChild(sp);	
		}
		else {
			var sp = document.createElement("textArea");
			sp.innerHTML = "success";
			var footerDiv = document.getElementById('copyright');
			footerDiv.appendChild(sp);	
		}
	}
	addUser = function() {
		var person_form = document.getElementById('person_form');
		//must add the '/' 
		var url = "/" + "<%= LocalContants.PROJECT_NAME %>" + "/personCreate.do";// + person_form.serialize();
		var pars = person_form.serialize();
		var myAjax = new Ajax.Request(url,{method:'post',parameters: pars,onComplete:callBack,evalScripts:true});
	}
	
	assignRole = function() {
		//add two containers' value to two result 
		var sel = document.getElementById("container1").childNodes;
		var selString = '';
		for(var i=0; i<sel.length; i++) {
			var item = sel[i].innerHTML;
			if(i == 0) {
				selString += sel[i].innerHTML;
			} else {
				selString += ';' + sel[i].innerHTML;					
			}
		}
		//--------------------------------------------------------
		var unsel = document.getElementById("container2").childNodes;
		var unselString = '';
		for(var i=0; i<unsel.length; i++) {
			var item = unsel[i].innerHTML;
			if(i == 0) {
				unselString += unsel[i].innerHTML;
			} else {
				unselString += ';' + unsel[i].innerHTML;					
			}
		}
		
		var selEle = document.getElementById('selrole');
		selEle.value = selString;
		var unselEle = document.getElementById('unselrole');
		unselEle.value = unselString;
		
		var role_form = document.getElementById('role_form');
		//must add the '/' 
		var url = "/" + "<%= LocalContants.PROJECT_NAME %>" + "/roleAssign.do";// + person_form.serialize();
		var pars = role_form.serialize();
		var myAjax = new Ajax.Request(url,{method:'post',parameters: pars,onComplete:callBack,evalScripts:true});
	}
	
	cancelAssign = function() {
		
	}
</script>

<%@ page import="java.util.*" %>
<%@ page import="com.esms.struts.service.*" %>
<%@ page language="java" contentType="text/html; charset=utf-8" %>